// mircoApp/cloud-pay-money/cloud_pay_money_sign.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jianzhimao_bank_show: false,
    set_verify: [],
    bank_card_status: false,
    pay_type:'cloud_pay_money_sign'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    console.log(this.options,'cloud_pay_money **********************')
    console.log(app.globalData.AppScene,'globalData.AppScene',app.globalData.cloud_pay_extraData)
    if(app.globalData.AppScene == 1038 && app.globalData.cloud_pay_extraData){
      this.confirmSign();
    }else{
      this.getData();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  closePopup(){
    this.getData();
  },
  confirmSign(){
    app._getNetWork({
      url: app.getNetAddresss("plugin.cloud-pay-money.frontend.controllers.sign.signing.sign-result"),
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          console.log(res.data,'confirmSign')
          app.globalData.cloud_pay_extraData = false;
          this.getData();
        } else {
          app.tips(res.msg);
          app.globalData.cloud_pay_extraData = false;
        }
      }
    });
  },
  getData() {
    wx.showLoading({
      title: '加载中',
    })
    app._getNetWork({
      url: app.getNetAddresss("plugin.cloud-pay-money.frontend.controllers.sign.signing"),
      success: (resdata) => {
        let res = resdata.data;
        wx.hideLoading();
        if (res.result == 1) {
          this.setData({
            info: res.data
          })
          console.log(res.data)
        } else {
          app.tips(res.msg);
        }
      },
      fail:()=>{
        wx.hideLoading();
      }
    });
  },
  toSignCloud() {
    if (this.data.info.status == 0 || this.data.info.status == "-1") {
      this.practitioner();
    }
  },
  practitioner() {
    app._getNetWork({
      url: app.getNetAddresss("plugin.cloud-pay-money.frontend.controllers.practitioner.practitioner"),
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          if (res.data.bank_card_status && res.data.member_info) {
            // 已经填过银行卡跟会员资料的直接请求签约路径
            this.signing();
            return;
          }
          this.setData({
            bank_card_status: res.data.bank_card_status,
            set_verify: res.data.member_set_verify,
            jianzhimao_bank_show: true
          })
        } else {
          app.tips(res.msg);
        }
      }
    });
  },
  signing() {
    app._getNetWork({
      url: app.getNetAddresss("plugin.cloud-pay-money.frontend.controllers.sign.signing.signing"),
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          wx.navigateToMiniProgram({
            appId: 'wxdbbe54cb39656067',
            path: `/pages/signAgreement/index?signId=${res.data.sign_url}`,
            envVersion: 'release'
          })
        } else {
          app.tips(res.msg);
        }
      }
    });
  }
})